package com.config.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * 统一结构封装
 * 后端发送命令前端接收
 */
@Data
@ApiModel (value="Result对象", description="")
public class Result implements Serializable {
	@ApiModelProperty (value = "接收状态（200正常，非200异常）")
	private int code; //200正常，非200异常
	@ApiModelProperty(value = "前端接收的操作反馈")
	private String msg;
	@ApiModelProperty(value = "前端接收的信息")
	private Object data;

	//成功
	public static Result succ(Object data) {
		return succ(200, "操作成功", data);
	}

	public static Result succ(int code, String msg, Object data) {
		Result r = new Result();
		r.setCode(code);
		r.setMsg(msg);
		r.setData(data);
		return r;
	}

	//失败
	public static Result fail(String msg) {
		return fail(400, msg, null);
	}

	public static Result fail(String msg, Object data) {
		return fail(400, msg, data);
	}

	public static Result fail(int code, String msg, Object data) {
		Result r = new Result();
		r.setCode(code);
		r.setMsg(msg);
		r.setData(data);
		return r;
	}
}
